package boundary;

import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

import entity.IOperatoerDTO;

public class Hovedmenu implements IHovedmenu {

	private Scanner scan;

	public Hovedmenu(Scanner scan){
		this.scan = scan;
	}

	@Override
	public int start(){
		System.out.println("Menu - vælg funktion");
		System.out.println("-----------------------------------------------");
		System.out.println("1: Operatør administration");
		System.out.println("");
		System.out.println("2: Brugers ændring af password");
		System.out.println("");
		System.out.println("3: Test applikation med password beskyttelse");
		System.out.println("");
		System.out.println("4: Afslut");
		System.out.println("-----------------------------------------------");
		int output = 0;
		try {
			output = scan.nextInt();
		} catch (InputMismatchException e){
			output = 0;
		} finally {
			scan.nextLine();
		}
		return output;
	}

	@Override
	public int oprAdminMenu() {
		System.out.println("Operatør Administration - vælg funktion");
		System.out.println("-----------------------------------------------");
		System.out.println("1: Opret operatør");
		System.out.println("");
		System.out.println("2: Slet operatør");
		System.out.println("");
		System.out.println("3: Ret operatør navn");
		System.out.println("");
		System.out.println("4: Vis operatører");
		System.out.println("");
		System.out.println("5: Vis inaktive operatører");
		System.out.println("");
		System.out.println("6: Nulstil operatørers password");
		System.out.println("");
		System.out.println("7: Afslut");
		System.out.println("-----------------------------------------------");
		int output = 0;
		try {
			output = scan.nextInt();
		} catch (InputMismatchException e){
			output = 0;
		} finally {
			scan.nextLine();
		}		
		return output;
	}

	@Override
	public int getUserID() {
		System.out.println("Indtast bruger/operatør ID: ");
		int output = -1;
		try {
			output = scan.nextInt();
			scan.nextLine();
		} catch (InputMismatchException e){
			System.out.println("Forkert bruger/operatør ID. Forsøg igen.");
			scan.nextLine();
			output = getUserID();
		} 
		return output;
	}

	@Override
	public String getUserPass() {
		System.out.println("Indtast password: ");
		String output = scan.nextLine();
		return output;
	}

	@Override
	public void loginStatus(boolean b) {
		String status;
		if (b){
			status = "godkendt.";
		} else {
			status = "afvist.";
		}
		System.out.println("Bruger ID og Password " + status);
	}

	@Override
	public String getUserNewPass() {
		System.out.println("Indtast nyt password: ");
		String output = scan.nextLine();
		return output;
	}

	@Override
	public void commandStatus(boolean b) {
		if (b){
			System.out.println("Kommandoen blev udført.");
		} else {
			System.out.println("Kommando afvist.");
		}
	}

	@Override
	public void showText(String text){
		System.out.println(text);
	}

	@Override
	public String oprForName(){
		System.out.println("Indtast fornavn(e):");
		String oprForNavn = scan.nextLine();
		return oprForNavn;
	}

	@Override
	public String oprLastName(){
		System.out.println("Indtast efternavn:");
		String oprEfterNavn = scan.nextLine();
		return oprEfterNavn;
	}

	@Override
	public String oprCpr(){
		System.out.println("Indtast CPR-nummer:");
		String cpr = scan.nextLine();
		return cpr;
	}

	@Override
	public void showOprCreated(String output){
		System.out.println("");
		System.out.println("Operatør oprettet!");
		System.out.println(output);
		System.out.println("-----------------------------------------------");
	}

	@Override
	public void listOpr(List<IOperatoerDTO> opr){
		System.out.println("-----------------------------------------------");
		System.out.println("ID: \t Initialer: \t Navn: \t CPR:");
		for (int i=0; i<opr.size(); i++){
			IOperatoerDTO oper = opr.get(i);
			System.out.println(oper);
		}
		System.out.println("-----------------------------------------------");
	}
}